local extension = Package:new("ysch1")
extension.extensionName = "ysch_Al"

local U = require "packages/utility/utility"

--添加英文到中文的翻译
Fk:loadTranslationTable{
  ["ysch1"] = "懿世春华",--小包名
  ["yschA"] = "懿世春华·子",--武将前缀
  ["yschB"] = "懿世春华·恋",--武将前缀
  ["yschC"] = "懿世春华·苍",--武将前缀
  ["yschD"] = "懿世春华·罔",--武将前缀
  ["yschE"] = "懿世春华·背",--武将前缀
  ["yschF"] = "懿世春华·誓",--武将前缀
  ["yschG"] = "懿世春华·心",--武将前缀
  ["yschH"] = "懿世春华·伤",--武将前缀
  ["ysch_Al"]='妍设长河',--大包名
  ["jin"] = "晋",
}

local zhangchunhuaA = General:new(extension, "yschA__zhangchunhua", "wei", 3, 3,General.Female)--
--local zhangchunhuaB = General:new(extension, "yschB__zhangchunhua", "wei", 3, 3,General.Female)--
local zhangchunhuaC = General:new(extension, "yschC__zhangchunhua", "wei", 4, 4,General.Female)--
local zhangchunhuaD = General:new(extension, "yschD__zhangchunhua", "wei", 3, 3,General.Female)--
local zhangchunhuaE = General:new(extension, "yschE__zhangchunhua", "wei", 3, 4,General.Female)--
--local zhangchunhuaF = General:new(extension, "yschF__zhangchunhua", "wei", 3, 4,General.Female)--
local zhangchunhuaG = General:new(extension, "yschG__zhangchunhua", "wei", 4, 4,General.Female)--
local zhangchunhuaH = General:new(extension, "yschH__zhangchunhua", "jin", 3, 3,General.Female)--

Fk:loadTranslationTable{
  ["yschA__zhangchunhua"] = "张春华",
  ["yschB__zhangchunhua"] = "张春华",
  ["yschC__zhangchunhua"] = "张春华",
  ["yschD__zhangchunhua"] = "张春华",
  ["yschE__zhangchunhua"] = "张春华",
  ["yschF__zhangchunhua"] = "张春华",
  ["yschG__zhangchunhua"] = "张春华",
  ["yschH__zhangchunhua"] = "张春华",
  --武将描述美化
  ["#yschA__zhangchunhua"] = "懿舐少华",
  ["#yschB__zhangchunhua"] = "懿世韶华",
  ["#yschC__zhangchunhua"] = "懿誓捎华",
  ["#yschD__zhangchunhua"] = "懿试烧华",
  ["#yschE__zhangchunhua"] = "懿恃劭华",
  ["#yschF__zhangchunhua"] = "懿失芍华",
  ["#yschG__zhangchunhua"] = "懿弑梢华",
  ["#yschH__zhangchunhua"] = "懿逝绍华",
  
  ["designer:yschA__zhangchunhua"] = "铝",
  ["cv:yschA__zhangchunhua"] = "未知",
  ["illustrator:yschA__zhangchunhua"] = "未知",
  ["designer:yschB__zhangchunhua"] = "铝",
  ["cv:yschB__zhangchunhua"] = "未知",
  ["illustrator:yschB__zhangchunhua"] = "七兜豆",
  ["designer:yschC__zhangchunhua"] = "铝",
  ["cv:yschC__zhangchunhua"] = "未知",
  ["illustrator:yschC__zhangchunhua"] = "未知",
  ["designer:yschD__zhangchunhua"] = "铝",
  ["cv:yschD__zhangchunhua"] = "未知",
  ["illustrator:yschD__zhangchunhua"] = "六道目",
  ["designer:yschE__zhangchunhua"] = "铝",
  ["cv:yschE__zhangchunhua"] = "未知",
  ["illustrator:yschE__zhangchunhua"] = "磐浦",
  ["designer:yschF__zhangchunhua"] = "铝",
  ["cv:yschF__zhangchunhua"] = "未知",
  ["illustrator:yschF__zhangchunhua"] = "未知",
  ["designer:yschG__zhangchunhua"] = "铝",
  ["cv:yschG__zhangchunhua"] = "未知",
  ["illustrator:yschG__zhangchunhua"] = "未知",
  ["designer:yschH__zhangchunhua"] = "铝",
  ["cv:yschH__zhangchunhua"] = "未知",
  ["illustrator:yschH__zhangchunhua"] = "未知",
}

local jidu = fk.CreateActiveSkill{
  name = "yschA_jidu",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#yschA_jidu",
  card_filter = function (self, to_select, selected)
    if #selected > 0 then return false end
    return table.contains({"slash", "jink"}, Fk:getCardById(to_select).trueName) and table.contains(Self:getCardIds("h"), to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("_yschA_jidu-phase") == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:setPlayerMark(target, "_yschA_jidu-phase", 1)
    room:moveCardTo(effect.cards, Card.PlayerHand, target, fk.ReasonGive, self.name, nil, false, player.id)
    player:drawCards(1, self.name)
    local cards = {}
    if not player.dead then
      for _, id in ipairs(U.prepareUniversalCards(room)) do
        local card = Fk:getCardById(id)
        if card.trueName == "slash" or card.trueName == "duel" then
          if target:canUseTo(card, player, {bypass_times = true, bypass_distances = true}) then
            table.insertIfNeed(cards, id)
          end
        end
      end
    end
    local name
    if #cards > 0 then
      local choices,_ = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name,
      "#yschA_jidu-choice:"..target.id.."::"..Fk:getCardById(effect.cards[1]):toLogString())
      if #choices > 0 then
        name = Fk:getCardById(choices[1]).name
      end
    end
    if name then
      if room:askForSkillInvoke(target, self.name, nil, "#yschA_jidu-use:"..player.id.."::"..Fk:getCardById(effect.cards[1]):toLogString()..":"..name) then
        local card = Fk:cloneCard(name)
        card.skillName = "yschA_jidu"
        card:addSubcard(effect.cards[1])
        room:useCard{
          from = target.id,
          card = card,
          tos = { { player.id } },
          extraUse = true,
        }
      end
    end
  end,
}
zhangchunhuaA:addSkill(jidu)
local chaixiao = fk.CreateTriggerSkill{
  name = "yschA_chaixiao",
  switch_skill_name = "yschA_chaixiao",
  anim_type = "drawcard",
  events = {fk.CardUsing, fk.CardResponding,fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
        return event == fk.TargetConfirmed and target == player and player:hasSkill(self)
      else
        return event ~= fk.TargetConfirmed and target == player and player:hasSkill(self)
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      if player:getHandcardNum() < player.maxHp then
        player:drawCards(player.maxHp - player:getHandcardNum(), self.name)
      end
    else
      room:askForDiscard(player, 1, 1, true, self.name)
    end
  end,

  refresh_events = {fk.DrawInitialCards},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name,fk.SwitchYin)
    player:setSkillUseHistory(self.name, 0, Player.HistoryGame)
  end,
}
zhangchunhuaA:addSkill(chaixiao)
Fk:loadTranslationTable{
  ["yschA_jidu"] = "笄笃",
  [":yschA_jidu"] = "出牌阶段每名角色限一次，你可以交给其他角色一张【闪】或【杀】并摸一张牌，然后其可以将此牌当你指定的【杀】或【决斗】对你使用。",
  ["#yschA_jidu"] = "笄笃：交给其他角色一张【闪】或【杀】并摸一张牌，然后其可以将此牌当你指定的【杀】或【决斗】对你使用",
  ["#yschA_jidu-choice"] = "笄笃：指定一种牌名，%src可将%arg当之对你使用",
  ["#yschA_jidu-use"] = "笄笃：是否将%arg当%arg2对%src使用",
  ["yschA_chaixiao"] = "钗销",
  [":yschA_chaixiao"] = "转换技，阴：当你使用或打出牌时，你弃置一张牌。阳：你成为牌的目标后摸至体力上限。",
}

local ShownCards = fk.CreateVisibilitySkill{
  name = "#Al_ShownCards",
  global = true,
  card_visible = function(self, player, card)
    if card:getMark("@@ShownCards-inhand") > 0 then
      return true
    end
  end
}
Fk:addSkill(ShownCards)
local qingleng = fk.CreateTriggerSkill{
  name = "yschC_qingleng",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  can_trigger = function (self, event, target, player, data)
    local room = player.room
    local x = player:getHandcardNum()
    local y = player:getHandcardNum()
    for _, p in ipairs(room.alive_players) do
      if p ~= player then
        x = math.min(x, p:getHandcardNum())
        y = math.max(y, p:getHandcardNum())
      end
    end
    return target==player and player:hasSkill(self) and y-x>0
  end,
  on_use = function(self, event, target, player, data)
    data.n = 0
    local room = player.room
    local x = player:getHandcardNum()
    local y = player:getHandcardNum()
    for _, p in ipairs(room.alive_players) do
      if p ~= player then
        x = math.min(x, p:getHandcardNum())
        y = math.max(y, p:getHandcardNum())
      end
    end
    local drawNum = math.min(9,y-x)
    local ids = room:getNCards(drawNum)
    room:moveCardTo(ids, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    local result = room:askForYiji(player, ids, nil, self.name, drawNum, drawNum, nil, ids)
    for _,ids in pairs(result) do
      if #ids > 0 then
        for _, id in ipairs(ids) do
          room:setCardMark(Fk:getCardById(id), '@@ShownCards-inhand', 1)
        end
      end
    end
    if not result[player.id] or #result[player.id]<3 then
      room:setPlayerMark(player, "@@ty_ex__shangshi", 1)
      room:handleAddLoseSkills(player, "ty_ex__shangshi", nil)
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@ty_ex__shangshi") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@ty_ex__shangshi", 0)
    room:handleAddLoseSkills(player, "-ty_ex__shangshi", nil)
  end,
}

local ty_ex__shangshi_discard = fk.CreateTriggerSkill{
  name = "#ty_ex__shangshi_discard",
  anim_type = "negative",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
     return target == player and player:hasSkill("ty_ex__shangshi") and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#shangshi-invoke")
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
  end,
}
local ty_ex__shangshi = fk.CreateTriggerSkill{
  name = "ty_ex__shangshi",
  anim_type = "drawcard",
  events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:getHandcardNum() < player:getLostHp() then
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          return move.from == player.id
        end
      else
        return target == player
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player:getLostHp() - player:getHandcardNum(), self.name)
  end,
}
ty_ex__shangshi:addRelatedSkill(ty_ex__shangshi_discard)
zhangchunhuaC:addSkill(qingleng)
zhangchunhuaC:addRelatedSkill(ty_ex__shangshi)

local moxin_recover = fk.CreateTriggerSkill{
  name = "#yschC_moxin_recover",
  --frequency = Skill.Compulsory,
  on_cost = Util.TrueFunc,
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self, true) and player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              return player:getMark("@@yschC_moxin_card") > 0 or player:getMark("@@yschC_moxin_hp") == 0
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes("yschC_moxin", Player.HistoryPhase) < 1 then
        room:setPlayerMark(player, "@@yschC_moxin_hp", 1)
    end
    if player:getMark("@@yschC_moxin_card") > 0 then
        room:setPlayerMark(player, "@@yschC_moxin_card", 0)
        room:notifySkillInvoked(player, self.name, 'negative')
        player:broadcastSkillInvoke(self.name)
        player:drawCards(1, self.name)
    else
        player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
    end
  end,
}
local moxin = fk.CreateTriggerSkill{
  name = "yschC_moxin",
  --frequency = Skill.Compulsory,
  on_cost = Util.TrueFunc,
  mute = true,
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 and target == player and player:hasSkill(self) and data.num < 0 and (player:getMark("@@yschC_moxin_card") == 0 or player:getMark("@@yschC_moxin_hp") > 0)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:usedSkillTimes("yschC_moxin_recover", Player.HistoryPhase) < 1 then
      room:setPlayerMark(player, "@@yschC_moxin_card", 1)
    end
    if player:getMark("@@yschC_moxin_hp") > 0 then
      room:setPlayerMark(player, "@@yschC_moxin_hp", 0)
      room:notifySkillInvoked(player, self.name, 'drawcard')
      player:broadcastSkillInvoke(self.name)
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = "yschC_moxin"
      })
    else
      player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
      p(self.name)
      p(player:usedSkillTimes(self.name, Player.HistoryPhase))
    end
  end,

  refresh_events = {fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    return player:getMark("@@yschC_moxin_hp") > 0 or player:getMark("@@yschC_moxin_card") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@yschC_moxin_hp", 0)
    room:setPlayerMark(player, "@@yschC_moxin_card", 0)
  end,
}
moxin:addRelatedSkill(moxin_recover)
zhangchunhuaC:addSkill(moxin)

Fk:loadTranslationTable{
  ['#Al_ShownCards'] = "明置",
  ["@@ShownCards-inhand"] = "明置",
  ["yschC_qingleng"] = "清冷",
  [":yschC_qingleng"] = "摸牌阶段，你可以改为亮出牌堆顶的X张牌，然后你分配并明置这些牌，若你以此法获得的牌数不大于2，你获得“伤逝”至下回合开始。（X为场上手牌数最值之差且至多为9）",
  ["@@ty_ex__shangshi"] = "伤逝",
  ["#ty_ex__shangshi_discard"] = "伤逝",
  ["ty_ex__shangshi"] = "伤逝",
  [":ty_ex__shangshi"] = "当你受到伤害时，你可以弃置一张牌。当你的手牌数小于X时，你可以将手牌摸至X张。（X为你已损失的体力值）",
  ["#shangshi-invoke"] = "伤逝：是否弃置一张手牌？",
  ["yschC_moxin"] = "陌心",
  [":yschC_moxin"] = "每回合每项限一次，你的体力值/手牌数减少后，本回合你下次手牌数/体力值减少时，你摸一张牌/回复1点体力。",
  ["#yschC_moxin_recover"] = "陌心",
  --['@@yschC_moxin'] = "陌心",
  ['@@yschC_moxin_card'] = "陌心 手牌",
  ['@@yschC_moxin_hp'] = "陌心 体力",
}

local chanqing_effect = fk.CreateActiveSkill{
  name = 'yschD_chanqing_effect',
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  prompt = function (self)
    return "#yschD_chanqing_effect:"..Self:getTableMark("yschD_chanqing_effect")[1]
  end,
  interaction = function()
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if (card.type == Card.TypeBasic or card.type == Card.TypeTrick) and card.sub_type ~= Card.SubtypeDelayedTrick and not card.multiple_targets and not card.is_derived and not table.contains(all_names, card.name) and card.name ~= 'jink' and card.name ~= 'nullification' then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        if ((Fk.currentResponsePattern == nil and (Self:canUse(to_use) or Fk:currentRoom():getPlayerById(Self:getTableMark("yschD_chanqing_effect")[1]):canUse(to_use)) and not Self:prohibitUse(to_use)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
          table.insert(names, card.name)
        end
      end
    end
    if #names == 0 then return false end
    return UI.ComboBox { choices = names, all_choices = all_names }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:usedSkillTimes("yschD_chanqing", Player.HistoryPhase) == 0
  end,
  card_filter = function (self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and (to_select == Self.id or table.contains(Self:getTableMark("yschD_chanqing_effect"), to_select)) and
    (Self:canUseTo(Fk:cloneCard(self.interaction.data),Fk:currentRoom():getPlayerById(to_select)) or Fk:currentRoom():getPlayerById(Self:getTableMark("yschD_chanqing_effect")[1]):canUseTo(Fk:cloneCard(self.interaction.data),Fk:currentRoom():getPlayerById(Self:getTableMark("yschD_chanqing_effect")[1])))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:handleAddLoseSkills(player, "-yschD_chanqing_effect", nil)
    local target = room:getPlayerById(effect.tos[1])
    local mark1 = player:getTableMark("yschD_chanqing_effect")
    table.insert(mark1, effect.tos[1])
    room:setPlayerMark(player, "yschD_chanqing_effect", mark1)
    room:handleAddLoseSkills(player, "yschD_chanqing_effect", nil)
    local mark2 = target:getTableMark("yschD_chanqing_effect")
    table.insert(mark2, effect.from)
    room:setPlayerMark(target, "yschD_chanqing_effect", mark2)
    room:handleAddLoseSkills(target, "yschD_chanqing_effect", nil)
    local use = {
      from = player.id,
      tos = table.map(effect.tos, function (id)
        return {id}
      end),
      card = Fk:cloneCard(self.interaction.data),
    }
    use.card:addSubcards(effect.cards)
    use.card.skillName = self.name
    room:useCard(use)
  end,
}
local chanqing = fk.CreateActiveSkill{
  name = 'yschD_chanqing',
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  prompt = "#yschD_chanqing",
  interaction = function()
    local names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if (card.type == Card.TypeBasic or card.type == Card.TypeTrick) and card.sub_type ~= Card.SubtypeDelayedTrick and not card.multiple_targets and not card.is_derived and not table.contains(names, card.name) then
        local to_use = Fk:cloneCard(card.name)
        if ((Fk.currentResponsePattern == nil and (Self:canUse(to_use) or card.name == 'peach') and not Self:prohibitUse(to_use)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
          table.insert(names, card.name)
        end
      end
    end
    if #names == 0 then return false end
    return UI.ComboBox { choices = names, all_choices = names }
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:usedSkillTimes("yschD_chanqing_effect", Player.HistoryPhase) == 0
  end,
  card_filter = function (self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and
    (Self:canUseTo(Fk:cloneCard(self.interaction.data),Fk:currentRoom():getPlayerById(to_select)) or Fk:currentRoom():getPlayerById(to_select):canUseTo(Fk:cloneCard(self.interaction.data),Fk:currentRoom():getPlayerById(to_select)))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:handleAddLoseSkills(player, "-yschD_chanqing", nil, true, false)
    local target = room:getPlayerById(effect.tos[1])
    local mark1 = player:getTableMark("yschD_chanqing_effect")
    table.insert(mark1, effect.tos[1])
    room:setPlayerMark(player, "yschD_chanqing_effect", mark1)
    room:setPlayerMark(player, "@yschD_chanqing_effect", Fk:translate(target.general))
    room:handleAddLoseSkills(player, "yschD_chanqing_effect", nil)
    local mark2 = target:getTableMark("yschD_chanqing_effect")
    table.insert(mark2, effect.from)
    room:setPlayerMark(target, "yschD_chanqing_effect", mark2)
    room:setPlayerMark(target, "@yschD_chanqing_effect", Fk:translate(player.general))
    room:handleAddLoseSkills(target, "yschD_chanqing_effect", nil)
    local use = {
      from = player.id,
      tos = table.map(effect.tos, function (id)
        return {id}
      end),
      card = Fk:cloneCard(self.interaction.data),
    }
    use.card:addSubcards(effect.cards)
    use.card.skillName = self.name
    room:useCard(use)
  end,
}
Fk:addSkill(chanqing_effect)
zhangchunhuaD:addSkill(chanqing)

local guyin = fk.CreateTriggerSkill{
  name = 'yschD_guyin',
  anim_type = "control",
  events = {fk.TurnEnd},
  frequency = Skill.Frequent,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@yschD_guyin") ~= 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local logic = room.logic
    while player:getMark("@yschD_guyin") ~= 0 do
      room:removePlayerMark(player, "@yschD_guyin", 1)
      player:drawCards(1, self.name)

      local data = { timeout = room.timeout }
      logic:trigger(fk.StartPlayCard, player, data, true)

      local req = Request:new(player, "PlayCard")
      req.timeout = data.timeout
      local result = req:getResult(player)

      if result ~= "" then
        local useResult = room:handleUseCardReply(player, result)
        if type(useResult) == "table" then
          room:useCard(useResult)
        end
      end
    end
  end,

  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return (target == player or #player.room.logic:getActualDamageEvents(1, function(e)
      return e.data[1].to == player
    end) > 0) and
      player:hasSkill(self) and
      (target.phase == Player.Judge  or target.phase == Player.Discard) and
      (#player:getCardIds(Player.Hand) == 0 or #player:getCardIds(Player.Judge) > 0)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name, 'negative')
    room:addPlayerMark(player, "@yschD_guyin", 1)
  end,
}
zhangchunhuaD:addSkill(guyin)

Fk:loadTranslationTable{
  ["yschD_chanqing"] = "缠情",
  [":yschD_chanqing"] = "出牌阶段同名技能限一次，你可以将一张牌当做单体即时牌对一名其他角色使用，然后你失去此技能，双方获得仅能对彼此中的角色发动的“缠情”。",
  ["#yschD_chanqing"] = "缠情：将一张牌当做单体即时牌对一名其他角色使用，然后你失去此技能，双方获得仅能对彼此中的角色发动的“缠情”",
  ["yschD_chanqing_effect"] = "缠情",
  ["@yschD_chanqing_effect"] = "缠情",
  ["#yschD_chanqing_effect"] = "缠情：将一张牌当做单体即时牌对你或%src使用，然后你失去此技能，双方获得仅能对彼此中的角色发动的“缠情”",
  [":yschD_chanqing_effect"] = "出牌阶段同名技能限一次，你可以将一张牌当做单体即时牌对你或“缠情角色”使用，然后你失去此技能，双方获得仅能对彼此中的角色发动的“缠情”。",
  ["yschD_guyin"] = "孤吟",
  ["@yschD_guyin"] = "孤吟",
  [":yschD_guyin"] = "你或你受到过伤害回合的判定或弃牌阶段开始时，若你判定区有牌或手牌区没牌，当前回合结束，你便可摸一张牌并执行一次出牌阶段空闲时间点结算。",
}

local yuanji = fk.CreateTriggerSkill{
  name = 'yschE_yuanji',
  anim_type = "offensive",
  events = {fk.PreDamage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and ((target == player ) or (data.to == player and player.shield>0 and player:isWounded()))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    local choice
    if target == player then
      table.insert(choices, "yschE_yuanji_hp")
    end
    if data.to and data.to == player and  player.shield>0  and player:isWounded() then
      table.insert(choices, "yschE_yuanji_shield")
    end
    if #choices == 1 then
      choice = choices[1]
    else
      choice = room:askForChoice(player, choices, self.name, "#yschE_yuanji-choice", false, choices)
    end
    if choice == "yschE_yuanji_hp" then
      room:loseHp(data.to, data.damage, self.name)
      room:changeShield(data.to, data.damage)
      data.damage = 0
    else
      local num = math.min(data.damage,player.shield,player.maxHp-player.hp)
      room:changeShield(data.to, -num)
      room:recover { num = num, skillName = self.name, who = player, recoverBy = player}
      data.damage=data.damage-num
    end
    if data.damage<=0 then
      return true
    end
  end,
}

local guifen__fireAttackSkill = fk.CreateActiveSkill{
  name = "yschE_guifen__fire_attack_skill",
  prompt = "#fire_attack_skill",
  target_num = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  target_filter = function(self, to_select, selected, selected_cards, card)
    if #selected < self:getMaxTargetNum(Self, card) then
      return self:modTargetFilter(to_select, selected, Self.id, card)
    end
  end,
  on_effect = function(self, room, cardEffectEvent)
    local from = room:getPlayerById(cardEffectEvent.from)
    local to = room:getPlayerById(cardEffectEvent.to)
    if to:isKongcheng() then return end

    local showCard = room:askForCard(to, 1, 1, false, "fire_attack_skill", false, ".|.|.|hand", "#fire_attack-show:" .. from.id)[1]
    local suit = Fk:getCardById(showCard):getSuitString()
    local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if use_event then
      local use = use_event.data[1]
      use.extra_data = use.extra_data or {}
      use.extra_data.yschE_guifen_show = use.extra_data.yschE_guifen_show or {}
      table.insertIfNeed(use.extra_data.yschE_guifen_show, {showCard})
    end
    to:showCards(showCard)

    if from.dead then return end

    local cards = room:askForDiscard(from, 1, 1, false, "fire_attack_skill", true,
      ".|.|" .. suit, "#fire_attack-discard:" .. to.id .. "::" .. suit, false)
    if #cards > 0 then
      room:damage({
        from = from,
        to = to,
        card = cardEffectEvent.card,
        damage = 1,
        damageType = fk.FireDamage,
        skillName = self.name,
      })
    end
  end,
}
guifen__fireAttackSkill.cardSkill = true
Fk:addSkill(guifen__fireAttackSkill)

local guifen = fk.CreateTriggerSkill{
  name = 'yschE_guifen',
  anim_type = "offensive",
  mute = true,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target==player and data.card.trueName == "fire_attack" and table.contains(data.card.skillNames, "yschE_guifen") then
      local cards = {}
      if data.extra_data and data.extra_data.yschE_guifen_show then
        for _,id in ipairs(data.extra_data.yschE_guifen_show) do
          local c = Fk:getCardById(id[1])
          if c.type==Card.TypeBasic or c:isCommonTrick() then
            table.insertIfNeed(cards, id[1])
          end
        end
      end
      local extra_data = { bypass_times = true }
      cards = table.filter(cards, function (id)
        local card = Fk:getCardById(id)
        return not player:prohibitUse(card) and player:canUse(card, extra_data)
      end)
      return #cards>0
    end
    local fire_attack = Fk:cloneCard("fire_attack")
    fire_attack.skillName = self.name
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn)
    return player:hasSkill(self) and (data.extra_data or {}).yschE_guifen and player:canUseTo(fire_attack, target) and (target==player or (turn_event ~= nil and turn_event.data[1] == player))
  end,
  on_cost = function (self, event, target, player, data)
    if target==player and data.card.trueName == "fire_attack" and table.contains(data.card.skillNames, "yschE_guifen") then
      return true
    else
      local room = player.room
      return room:askForSkillInvoke(player, self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.extra_data and data.extra_data.yschE_guifen_show then
      local cards = {}
      if data.extra_data and data.extra_data.yschE_guifen_show then
        for _,id in ipairs(data.extra_data.yschE_guifen_show) do
          local c = Fk:getCardById(id[1])
          if c.type==Card.TypeBasic or c:isCommonTrick() then
            table.insertIfNeed(cards, id[1])
          end
        end
      end
      local extra_data = { bypass_times = true }
      cards = table.filter(cards, function (id)
        local card = Fk:getCardById(id)
        return not player:prohibitUse(card) and player:canUse(card, extra_data)
      end)
      local use = U.askForUseRealCard(room, player, cards, nil, "yschE_guifen_effect", "#yschE_guifen-use",
        {expand_pile = cards, bypass_times = true, extraUse = true}, true, true)
      if use then
        room:notifySkillInvoked(player, self.name, 'offensive')
        use = {
          card = Fk:cloneCard(use.card.name),
          from = player.id,
          tos = use.tos,
        }
        use.card.skillName = "yschE_guifen_effect"
        room:useCard(use)
      end
    else
      room:notifySkillInvoked(player, self.name, 'offensive')
      local fire_attack = Fk:cloneCard("fire_attack")
      fire_attack.skillName = self.name
      room:useCard{
        from = player.id,
        card = fire_attack,
        tos = {{target.id}},
      }
    end
  end,

  refresh_events = {fk.CardShown, fk.Death,fk.PreCardUse,fk.PreCardEffect},
  can_refresh = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return data.from == player.id and data.card.trueName == "fire_attack" and table.contains(data.card.skillNames, "yschE_guifen")
    elseif event == fk.PreCardUse then
      p(player:hasSkill(self) and
      data.card:getMark("@@yschE_guifen-turn") == 0 and ((data.card:isVirtual() and #data.card.subcards > 0) or not data.card:isVirtual()) and data.card.type == Card.TypeTrick)
      return player:hasSkill(self) and
        data.card:getMark("@@yschE_guifen-turn") == 0 and ((data.card:isVirtual() and #data.card.subcards > 0) or not data.card:isVirtual()) and data.card.type == Card.TypeTrick
    elseif event == fk.CardShown then
      return player:hasSkill(self, true)
    elseif event == fk.Death then
      return player == target
    else
      return true
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("yschE_guifen-turn")
    if event == fk.PreCardEffect then
      local card = data.card:clone()
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        card[k] = v
      end
      card.skill = guifen__fireAttackSkill
      data.card = card
    elseif event == fk.PreCardUse then
      data.extra_data = data.extra_data or {}
      data.extra_data.yschE_guifen = true
    elseif event == fk.CardShown then
      for _, id in ipairs(data.cardIds) do
        if Fk:getCardById(id).type == Card.TypeTrick and Fk:getCardById(id):getMark("@@yschE_guifen-turn") == 0 and table.contains(target:getCardIds("h"), id) then
          table.insert(mark, id)
          room:setCardMark(Fk:getCardById(id, true), "@@yschE_guifen-turn", 1)
        end
      end
    else
      local card
      for _, id in ipairs(mark) do
        card = Fk:getCardById(id)
        if card:getMark("@@yschE_guifen-turn") > 0 and table.every(room.alive_players, function (p)
          return not table.contains(p:getTableMark("yschE_guifen-turn"), id)
        end) then
          room:setCardMark(card, "@@yschE_guifen-turn", 0)
        end
      end
    end
    room:setPlayerMark(player, "yschE_guifen-turn", mark)
  end,
}

zhangchunhuaE:addSkill(yuanji)
zhangchunhuaE:addSkill(guifen)

Fk:loadTranslationTable{
  ["yschE_yuanji"] = "怨积",
  [":yschE_yuanji"] = "你即将造成/受到的伤害可以改为将受伤角色等量体力/护甲转换为另一项。",
  ["yschE_yuanji_hp"] = "体力",
  ["yschE_yuanji_shield"] = "护甲",
  ["#yschE_yuanji-choice"] = "怨积：将体力或护甲转换为另一项。",
  ["yschE_guifen"] = "闺愤",
  [":yschE_guifen"] = "你或你回合内的角色使用本回合未展示过的锦囊牌结算完成后，你可以视为对其使用一张【火攻】，然后视为使用展示的即时牌。",
  ["@@yschE_guifen-turn"] = "闺愤",
  ["yschE_guifen_effect"] = "闺愤",
  ["#yschE_guifen-use"] = "闺愤：你可以视为使用其中一张牌"

}

local ningai = fk.CreateActiveSkill{
  name = "yschG_ningai",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#yschG_ningai",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 2 or table.contains(Self:getMark("yschG_ningai-phase"), player.id)
  end,
  card_filter = function(self, to_select, selected)
    return false
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected > 0 then return false end
    if Self.id == to_select then return true end
    local card = Fk:cloneCard("ice__slash")
    card.skillName = self.name
    return (Self:getMark("yschG_ningai-phase") == 0 or not table.contains(Self:getMark("yschG_ningai-phase"), to_select)) and not Self:isProhibited(Fk:currentRoom():getPlayerById(to_select), card)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])

    local mark = player:getMark("yschG_ningai-phase")
    if mark == 0 then mark = {} end
    table.insert(mark, target.id)
    room:setPlayerMark(player, "yschG_ningai-phase", mark)

    local card = Fk:cloneCard("ice__slash")
    card.skillName = self.name
    room:useCard{
      from = effect.from,
      tos = table.map(effect.tos, function(id) return {id} end),
      card = card,
    }
  end
}
local jinjue = fk.CreateTriggerSkill{
  name = "yschG_jinjue",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    local resp_players = {}
    local use_events = room.logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    local cards = data.cardsResponded
    if cards ~= nil then
      for i = #use_events, 1, -1 do
        local e = use_events[i]
        local use = e.data[1]
        if e.data[1] == data then break end
        if table.contains(cards, use.card) then
          table.insert(resp_players, use.from)
        end
      end
    end
    local currents = player:getMark("yschG_jinjue")
    if currents == 0 then currents = {} end
    if #currents == 0 then return false end
    table.filter(currents, function (id)
      return not player:prohibitUse(data.card) and not player:isProhibited(Fk:currentRoom():getPlayerById(id), data.card)
    end)
    return player:hasSkill(self) and data.card.trueName == "slash" and data.tos and #data.tos == 1 and table.contains(TargetGroup:getRealTargets(data.tos), player.id) and not table.contains(resp_players, player.id) and #currents>0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local currents = player:getMark("yschG_jinjue")
    table.filter(currents, function (id)
      return not player:prohibitUse(data.card) and not player:isProhibited(Fk:currentRoom():getPlayerById(id), data.card)
    end)
    room:useCard{from = player.id,tos = {currents},card = data.card,extraUse = true,}
  end,

  refresh_events = {fk.AfterCardsMove,fk.Damaged,fk.Deathed},
  can_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.Deathed then
      return target == player or table.contains(player:getMark("yschG_jinjue"), target.id)
    elseif event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from == player.id and move.to and move.to ~= player.id
        and not room:getPlayerById(move.to).dead and move.toArea == Card.PlayerHand then
          return true
        end
      end
    else
      return data.from and not data.from.dead and data.from ~= player and target == player
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.Deathed then
      if target == player then
        for _, p in ipairs(room:getAlivePlayers()) do
          room:setPlayerMark(player, "yschG_jinjue", {})
          room:setPlayerMark(p, "@@yschG_jinjue", 0)
        end
      else
        local mark = player:getMark("yschG_jinjue")
        if mark == 0 then mark = {} end
        table.remove(mark, target.id)
        room:setPlayerMark(player, "yschG_jinjue", mark)
        room:setPlayerMark(target, "@@yschG_jinjue", 0)
      end
    else
      local list = {}
      if event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.from == player.id and move.to and move.to ~= player.id
          and not room:getPlayerById(move.to).dead and move.toArea == Card.PlayerHand then
            table.insertIfNeed(list,move.to)
          end
        end
      else
        table.insertIfNeed(list,data.from.id)
      end
      local mark = player:getMark("yschG_jinjue")
      if mark == 0 then mark = {} end
      for _, p in ipairs(room:getAlivePlayers()) do
        if table.contains(list, p.id) then
          table.insert(mark, p.id)
          room:setPlayerMark(player, "yschG_jinjue", mark)
          if player:hasSkill(self) then room:setPlayerMark(p, "@@yschG_jinjue", 1) end
        else
          if table.contains(mark,p.id) then
            table.remove(mark, p.id)
            room:setPlayerMark(player, "yschG_jinjue", mark)
            room:setPlayerMark(p, "@@yschG_jinjue", 0)
          end
        end
      end
    end
  end,
}
zhangchunhuaG:addSkill(ningai)
zhangchunhuaG:addSkill(jinjue)

Fk:loadTranslationTable{
  ["yschG_ningai"] = "凝哀",
  [":yschG_ningai"] = "出牌阶段限两次且每名角色限一次，你可视为对一名角色使用冰【杀】。若为你，本回合此技能对你无次数限制。",
  ["#yschG_ningai"] = "凝哀：视为对一名角色使用冰【杀】",
  ["yschG_jinjue"] = "尽决",
  [":yschG_jinjue"] = "锁定技，以你为唯一目标的【杀】结算完成后，若你未响应此牌，视为你对上一名获得你的牌或对你造成伤害的其他角色使用此【杀】。",
  ["@@yschG_jinjue"] = "尽决",
}

local hidden_skill = fk.CreateTriggerSkill{
  name = "yschH_hongyin_hidden_skill&",
  global = true,
  priority = 0.001,
  refresh_events = {fk.GamePrepared},
  can_refresh = function (self, event, target, player, data)
    if not player:hasSkill("hidden_skill&") then return false end
    local general = Fk.generals[player:getMark("__hidden_general")]
    local deputy = Fk.generals[player:getMark("__hidden_deputy")]
    local skills1,skills2 = {},{}
    if general then
      skills1 = general:getSkillNameList(true)
    end
    if deputy then
      skills2 = deputy:getSkillNameList(true)
    end
    return table.contains(skills1,'yschH_hongyin') or table.contains(skills2,'yschH_hongyin')
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local general = Fk.generals[player:getMark("__hidden_general")]
    local skills1 = general:getSkillNameList(true)
    if table.contains(skills1,'yschH_hongyin') then
      room:setPlayerMark(player, "#yschH_hongyin_general", player:getMark("__hidden_general"))
      room:setPlayerMark(player, "__hidden_general", "ol__simayi")
    else
      room:setPlayerMark(player, "#yschH_hongyin_deputy", player:getMark("__hidden_deputy"))
      room:setPlayerMark(player, "__hidden_deputy", "ol__simayi")
    end
    room:handleAddLoseSkills(player, "#yschH_hongyin", nil, false, true)
  end,
}
Fk:addSkill(hidden_skill)
local hongyin = fk.CreateTriggerSkill{
  name = 'yschH_hongyin',
  isHiddenSkill = true,
}
hongyin.isHiddenSkill=true
local hongyin_skill = fk.CreateTriggerSkill{
  name = '#yschH_hongyin',
  refresh_events = {fk.SkillEffect},
  can_refresh = function(self, event, target, player, data)
    local skills = Fk.generals["ol__simayi"]:getSkillNameList(true)
    skills = table.filter(skills,function (skill_name)
      local skill = Fk.skills[skill_name]
      return skill.frequency ~= 3 and not skill.isHiddenSkill and skill_name ~= "yingshis"
    end)
    return player:hasSkill(self.name) and table.contains(skills,data.name)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local init = true
    local list = player:getTableMark("#yschH_hongyin_skill");
    table.insertIfNeed(list, data.name)
    room:setPlayerMark(player, "#yschH_hongyin_skill", list)
    local skills = Fk.generals["ol__simayi"]:getSkillNameList(true)
    skills = table.filter(skills,function (skill_name)
      local used = player:getTableMark("#yschH_hongyin_skill")
      local skill = Fk.skills[skill_name]
      if skill.frequency ~= 3 and not skill.isHiddenSkill and skill_name ~= "yingshis" then
        if not table.contains(used,skill_name) then
          init = false
        end
      end
    end)
    if init then
      local general = true
      room:handleAddLoseSkills(player, "-#yschH_hongyin", nil, false, true)
      room:notifySkillInvoked(player, "yschH_hongyin", 'defensive')
      if player:getMark("#yschH_hongyin_general") and Fk.generals[player:getMark("#yschH_hongyin_general")] then
        room:changeHero(player, player:getMark("#yschH_hongyin_general"), false, false, true, false)
      elseif player:getMark("#yschH_hongyin_deputy") and Fk.generals[player:getMark("#yschH_hongyin_deputy")] then
        general = false
        room:changeHero(player, player:getMark("#yschH_hongyin_deputy"), false, true, true, false)
      end
      if player:hasSkill("yschH_mufeng$") then
        if room:askForSkillInvoke(target, "yschH_mufeng$", nil, "#yschH_mufeng$") then
          if player:isWounded() and not player.dead then
            room:recover({
              who = player,
              num = player.maxHp - player.hp,
              recoverBy = player,
              skillName = "yschH_mufeng$",
            })
          end
          player:setSkillUseHistory("xiongzhi", 0, Player.HistoryGame)
          if general then
            room:changeHero(player, "ol__yschH_simayi", false, false, true, false)
          else
            room:changeHero(player, "ol__yschH_simayi", false, true, true, false)
          end
        end
      end
    end
  end,
}
Fk:addSkill(hongyin_skill)
local jianmie = fk.CreateTriggerSkill{
  name = "yschH_jianmie",
  anim_type = "offensive",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#yschH_jianmie-invoke::"..data.to.id..":"..data.damage)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:loseHp(player, 1, self.name)
    data.damage = data.damage * 2
    local x, y = player:getLostHp(), player:getHandcardNum()
    if x < y then
      room:askForDiscard(player, 1, 1, false, self.name, false)
    elseif x > y then
      player:drawCards(1, self.name)
    else
      if #room:askForDiscard(player, 1, 1, false, self.name, true, nil, "#yschH_jianmie-discard") == 0 then
        player:drawCards(1, self.name)
      end
    end
  end,
}
local luoqing = fk.CreateTriggerSkill{
  name = "yschH_luoqing",
  mute = true,
  events = {fk.PreCardUse},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.is_damage_card
  end,
  on_cost = function(self, event, target, player, data)
    return target.room:askForSkillInvoke(target, "PlayCard", nil, "#yschH_luoqing")
  end,
  on_use = function(self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.yschH_luoqing=player
  end,

  refresh_events = {fk.AskForCardResponse,fk.AskForCardUse},
  can_refresh = function (self, event, target, player, data)
    return data.eventData and data.eventData.extra_data and data.eventData.extra_data.yschH_luoqing == player and not data.eventData.extra_data.yschH_luoqing_ed
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    local event_Data = {}
    for index,_ in pairs(data.eventData) do
      event_Data[index] = data.eventData[index]
    end
    event_Data.extra_data.yschH_luoqing_ed = true
    local prompt = nil
    if data.eventData.card.trueName == "slash"  then
      prompt = "#slash-jink:" .. player.id
    end
    if event == fk.AskForCardResponse then
      local cardResponded = room:askForResponse(data.user, data.cardName, data.pattern, prompt, true, data.extra_data, event_Data)
      if cardResponded then
        room:responseCard({
          from = data.user.id,
          card = cardResponded,
        })
      end
    else
      local use = room:askForUseCard(data.user, data.cardName, data.pattern, prompt, true, data.extra_data, event_Data)
      if use then
        room:useCard(use)
      end
    end
    room:notifySkillInvoked(player, "yschH_luoqing", 'defensive')
  end,
}
local mufeng = fk.CreateTriggerSkill{
  name = 'yschH_mufeng$',
}
local yishi_zhangchunhua = fk.CreateTriggerSkill{
  name = "yschH__intro_zhangchunhua"
}
zhangchunhuaH:addSkill(hongyin)
zhangchunhuaH:addSkill(jianmie)
zhangchunhuaH:addSkill(luoqing)
zhangchunhuaH:addSkill(mufeng)
zhangchunhuaH:addRelatedSkill(yishi_zhangchunhua)

Fk:loadTranslationTable{
  ["yschH_hongyin"] = "薨隐",
  [":yschH_hongyin"] = "隐匿技，你登场时改为登场“晋司马懿”，于其非锁定非隐匿技均发动后变回此武将牌。",
  ["yschH_jianmie"] = "剪灭",
  [":yschH_jianmie"] = "当你造成伤害时，你可以失去1点体力令伤害翻倍，然后将手牌数向已损体力值调整1。",
  ["#yschH_jianmie-invoke"] = "剪灭：是否失去1点体力令即将对%dest造成的%arg点伤害翻倍",
  ["#yschH_jianmie-discard"] = "剪灭：弃置一张牌或摸一张牌",
  ["yschH_luoqing"] = "洛卿",
  [":yschH_luoqing"] = "当你使用伤害牌时，你可以秘密选择是否在此牌响应前进行一次虚假的响应询问。",
  ["#yschH_luoqing"] = "洛卿：是否发动“洛卿”，令此牌响应前进行一次虚假的响应询问",
  ["yschH_mufeng"] = "穆凤",
  [":yschH_mufeng"] = "主公技，当你发动“薨隐”变回本体时，可以改为回复所有体力，并变为初版“晋司马懿”。",
  ["#yschH_mufeng$"] = "穆凤：是否发动“穆凤”，回复所有体力，并变为初版“晋司马懿”",
  ["yschH__intro_zhangchunhua"]="佚史",
  [":yschH__intro_zhangchunhua"]="这个武将有段神秘的故事......<br><a href=':intro__parallel__zhangchunhua'>《晋书·宣穆张皇后传》</a>",
  [":intro__parallel__zhangchunhua"] = [[ ㅤㅤ<b>《晋书·宣穆张皇后传》</b>
<br> ㅤㅤ宣穆张皇后，讳春华，河内平皋人也，晋宣帝司马懿之妻。后性贞淑而有机智，内助宣帝，甚有德誉。
<br> ㅤㅤ正始八年，宣帝疾笃，薨于洛阳。时曹爽专政，权倾朝野。后恐家族蒙难，乃行权变之计，秘不发丧，假托宣帝之名，上书告老，以避爽之锋芒，以退为进，实乃韬光养晦之策。
<br> ㅤㅤ越二年，至正始十年，后乘曹爽兄弟出城之际，密结忠良，发动高平陵之变，诛爽及其党羽，定司马氏之基业。后虽身居幕后，然其智勇深沉，不亚须眉，运筹帷幄，决胜千里。
<br> ㅤㅤ嘉平三年，后因思夫过度，积忧成疾，终至不起，溘然长逝，与宣帝合葬。后之薨逝，举国哀悼，朝野上下皆感其贤德与智勇。后世论及，皆以后为女中豪杰，能与夫共谋大事，亦能独当一面，此非寻常女子所能为也。
<br> ㅤㅤ史臣曰：宣穆张皇后以女子之身，辅佐宣帝，共谋大业，其智勇才略，不让须眉，非但妇人之仁所能及。假死避祸，借势反击，终成大业，实为巾帼英雄之典范。故特书其事，以彰其德，垂范后世。]],
}

local ol_simayi = General:new(extension, "ol__yschH_simayi", "jin", 3, 3)--
ol_simayi.hidden=true
Fk:loadTranslationTable{
  ["ol__yschH_simayi"] = "旧司马懿",
  ["#ol__yschH_simayi"] = "通权达变",
  ["illustrator:ol__yschH_simayi"] = "六道目",

  ["$yschH_quanbian1"] = "筹权谋变，步步为营。",
  ["$yschH_quanbian2"] = "随机应变，谋国窃权。",
  ["~ol__yschH_simayi"] = "虎入骷冢，司马难兴。",
}
local quanbian = fk.CreateTriggerSkill{
  name = "yschH_quanbian",
  anim_type = "drawcard",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Play and data.card.suit ~= Card.NoSuit and
      U.IsUsingHandcard(player, data) then
      local card_suit = data.card.suit
      local room = player.room
      local logic = room.logic
      local current_event = logic:getCurrentEvent()
      local mark_name = "yschH_quanbian_" .. data.card:getSuitString() .. "-phase"
      local mark = player:getMark(mark_name)
      if mark == 0 then
        logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data[1]
          if use.from == player.id and use.card.suit == card_suit and U.IsUsingHandcard(player, e.id) then
            mark = e.id
            return true
          end
          return false
        end, Player.HistoryPhase)
        logic:getEventsOfScope(GameEvent.RespondCard, 1, function (e)
          local use = e.data[1]
          if use.from == player.id and use.card.suit == card_suit and U.IsUsingHandcard(player, e.id) then
            mark = (mark == 0) and e.id or math.min(e.id, mark)
            return true
          end
          return false
        end, Player.HistoryPhase)
        room:setPlayerMark(player, mark_name, mark)
      end
      return mark == current_event.id
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark("@yschH_quanbian-phase")
    if not table.contains(mark, data.card:getSuitString(true)) then
      table.insert(mark, data.card:getSuitString(true))
    end
    player.room:setPlayerMark(player, "@yschH_quanbian-phase", mark)
    self:doCost(event, target, player, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_cards = room:getNCards(player.maxHp)
    local suits = {"spade", "club", "heart", "diamond"}
    table.remove(suits, data.card.suit)
    local cardmap = room:askForArrangeCards(player, "yschH_quanbian", {all_cards, "Top", "Bottom"}, "#yschH_quanbian-get", false, 0,
    {#all_cards, 1}, {0,0})
    for i = #cardmap[1], 1, -1 do
      table.insert(room.draw_pile, 1, cardmap[1][i])
    end
    if #cardmap[2] > 0 then
      table.insert(room.draw_pile, cardmap[2][1])
    else
      player:drawCards(1, self.name)
    end
    local mark = player:getTableMark("#yschH_quanbian-phase")
    table.insert(mark, data.card:getSuitString(true))
    player.room:setPlayerMark(player, "#yschH_quanbian-phase", mark)
  end,
}
local quanbian_prohibit = fk.CreateProhibitSkill{
  name = "#yschH_quanbian_prohibit",
  prohibit_use = function(self, player, card)
    if player:hasSkill(quanbian) and player.phase == Player.Play then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return player:getMark("#yschH_quanbian-phase") ~= 0 and table.contains(player:getMark("#yschH_quanbian-phase"), card:getSuitString(true)) and #subcards > 0 and table.every(subcards, function(id)
        return table.contains(player:getCardIds(Player.Hand), id)
      end)
    end
  end,
}
quanbian:addRelatedSkill(quanbian_prohibit)
ol_simayi:addSkill("buchen")
ol_simayi:addSkill("yingshis")
ol_simayi:addSkill("xiongzhi")
ol_simayi:addSkill(quanbian)
Fk:loadTranslationTable{
  ["yschH_quanbian"] = "权变",
  [":yschH_quanbian"] = "当你于出牌阶段首次使用或打出一种花色的手牌时，你可以摸一张牌，或将牌堆顶X张牌中的一张牌置于牌堆底（X为你的体力上限）。若如此做，本回合你不能再使用此花色的手牌。",
  ["@yschH_quanbian-phase"] = "权变",
  ["#yschH_quanbian-get"] = "权变：将一张牌置于牌堆底或摸一张牌",
}

return extension--